package com.ic.controller;

import com.ic.domain.Device;
import com.ic.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @GetMapping("")
    public List<Device> list() {
        return deviceService.findAll();
    }

    @GetMapping("/{deviceId}")
    public Device get(@PathVariable String deviceId) {
        return deviceService.findById(deviceId);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity delete(@PathVariable String id) {
        deviceService.delete(id);
        return ResponseEntity.ok().build();
    }

    @PostMapping("")
    public String add(@RequestBody Device device) {
        deviceService.save(device);
        return "";
    }
}
